﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Mooc
{
    public partial class EduApp : Form
    {
        public EduApp(Home home, Edu edu)
        {
            InitializeComponent();
            this.home = home;
            this.edu = edu;
            getWork();
        }
        Home home;

        Edu edu;

        SqlDao sqlDao = new SqlDao();

        bool e1 = true;
        private void getWork()
        {
            DataSet ds = sqlDao.selectWorkedByState(1);
            if (ds.Tables[0].Rows.Count > 0)
            {
                dataGridView1.DataSource = ds.Tables[0].DefaultView;
                if (e1)
                {
                    DataGridViewButtonColumn column = new DataGridViewButtonColumn();
                    column.Text = "抽 检";
                    column.Name = "编 辑";
                    column.UseColumnTextForButtonValue = true;
                    dataGridView1.Columns.Add(column);
                    dataGridView1.Columns[4].Width = 400;
                    e1 = false;
                }
            }
        }

        private void tabControl1_Selected(object sender, TabControlEventArgs e)
        {
            if (e.TabPageIndex == 0)
            {
                getWork();
            }
            else
            {
                if (MessageBox.Show("确定要退出...", "警告", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    home.openForm(new Login(home));
            }
        }

        int index;

        public void delete()
        {
            dataGridView1.Rows.RemoveAt(index);
        }
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                index = e.RowIndex;
                Work work = new Work();
                work.W_score = dataGridView1.Rows[e.RowIndex].Cells["分数"].Value.ToString();
                work.W_id = dataGridView1.Rows[e.RowIndex].Cells["作业ID"].Value.ToString();
                work.W_content = dataGridView1.Rows[e.RowIndex].Cells["作业内容"].Value.ToString();
                work.W_comment = dataGridView1.Rows[e.RowIndex].Cells["评语"].Value.ToString();

                Opi opi = new Opi();
                opi.E_id = edu.E_id;
                updateOpinion updateOpinion = new updateOpinion(work,opi, this);
                updateOpinion.ShowDialog();
            }
        }
    }
}
